package jp.co.apl.haven.util;

import java.util.Arrays;
import java.util.List;

import jp.co.apl.haven.generated.HavenProtos.BasicInfoItem;
import jp.co.apl.haven.generated.HavenProtos.BasicInfoSelectionItem;
import jp.co.apl.haven.generated.HavenProtos.InputType;
import jp.co.apl.haven.generated.HavenProtos.Question;
import jp.co.apl.haven.generated.HavenProtos.SelectionItem;

import com.google.common.collect.Lists;

public class HavenProtosUtil {

    private HavenProtosUtil() {
    }

    public static Question q(int id, String title, String text,
            SelectionItem... selections) {
        return Question
            .newBuilder()
            .setId(id)
            .setQuestionId(id)
            .setTitle(title)
            .setText(text)
            .setInputType(InputType.SELECT)
            .addAllSelectionItem(Lists.newArrayList(selections))
            .build();
    }

    public static Question q(int id, String title, String text, String unit) {
        return Question
            .newBuilder()
            .setId(id)
            .setQuestionId(id)
            .setTitle(title)
            .setText(text)
            .setInputType(InputType.NUMBER)
            .setUnit(unit)
            .build();
    }

    public static Question cq(int id, String title, String text,
            SelectionItem... selections) {
        return Question
            .newBuilder()
            .setId(id)
            .setQuestionId(id)
            .setTitle(title)
            .setText(text)
            .setInputType(InputType.SELECT)
            .addAllSelectionItem(Lists.newArrayList(selections))
            .build();
    }

    public static Question cq(int id, String title, String text, String unit) {
        return Question
            .newBuilder()
            .setId(id)
            .setQuestionId(id)
            .setTitle(title)
            .setText(text)
            .setInputType(InputType.NUMBER)
            .setUnit(unit)
            .build();
    }

    public static SelectionItem sel(String item, Question... childQuestions) {
        return SelectionItem
            .newBuilder()
            .setValue(item)
            .setLabel(item)
            .addAllChildQuestion(qlist(childQuestions))
            .build();
    }

    public static List<Question> qlist(Question... questions) {
        return Arrays.asList(questions);
    }

    public static BasicInfoItem b1(int id, String name,
            BasicInfoSelectionItem... selections) {
        return BasicInfoItem
            .newBuilder()
            .setBasicInfoItemId(id)
            .setName(name)
            .addAllBasicInfoSelectionItem(Arrays.asList(selections))
            .setInputType(InputType.SELECT)
            .build();
    }

    public static BasicInfoItem b2(int id, String name) {
        return BasicInfoItem
            .newBuilder()
            .setBasicInfoItemId(id)
            .setName(name)
            .setInputType(InputType.TEXT)
            .build();
    }

    public static BasicInfoSelectionItem bsel(String value, String label) {
        return BasicInfoSelectionItem
            .newBuilder()
            .setValue(value)
            .setLabel(label)
            .build();
    }

}
